package com.macro.mall.es.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.dto.EsIndexDto;
import com.macro.mall.es.dto.DocSearchRequest;
import com.macro.mall.es.dto.DocSearchResponse;
import com.macro.mall.es.service.EsService;
import com.macro.mall.model.PmsBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author：尚志豪
 * @Package：com.macro.mall.es.controller
 * @Project：mall-swarm
 * @name：EsController
 * @Date：2024/10/20 14:26
 */
@RestController
@RequestMapping("/index")
public class EsController {
    @Autowired
    private EsService esService;

    /**
     * 创建产品索引
     * @param esIndexDto
     * @return
     */
    @PostMapping("/creatProductIndex")
    public CommonResult creatProductIndex(@Validated @RequestBody EsIndexDto esIndexDto){
        return esService.creatProductIndex(esIndexDto);
    }

    /**
     * 根据索引名称搜索产品索引
     */
    @PostMapping("/searchProduct/{indexName}")
    public CommonResult<Map<String,Object>> creatProductIndex(@PathVariable String indexName) {
        return esService.searchProductIndex(indexName);
    }

    /**
     * 检查索引是否存在
     */
    @PostMapping("/searchIndexChecker/{indexName}")
    public CommonResult searchIndexChecker(@PathVariable String indexName){
        return esService.searchIndexChecker(indexName);
    }

    /**
     * 更新产品索引
     */
    @PostMapping("/updateIndexProduct")
    public CommonResult updateIndexProduct(@Validated @RequestBody EsIndexDto esIndexDto){
        return esService.updateIndexProduct(esIndexDto);
    }

    /**
     * 删除指定的产品索引
     */
    @PostMapping("/del/{indexName}")
    public CommonResult delProductIndex(@PathVariable String indexName) {
        return esService.delProductIndex(indexName);
    }

    /**
     * 搜索
     */
    @PostMapping("/search")
    public List<DocSearchResponse> search(@RequestBody DocSearchRequest docSearchRequest) {
        return esService.search(docSearchRequest);
    }

}
